home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / vol11n06.zip / MIDIDEVS.C < prev    next >
C/C++ Source or Header  |  1991-11-21  |  7KB  |  189 lines

  1. /*-----------------------------------------------------------
  2.    MIDIDEVS.C -- Multimedia Windows MIDI Device Capabilities
  3.                  (c) Charles Petzold, 1992
  4.   -----------------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include <mmsystem.h>
  8. #include <string.h>
  9.  
  10. #define OUT TextOut (hdc, x, y, szBuffer, strlen (szBuffer)) ; y += cyChar ;
  11.  
  12. long FAR PASCAL WndProc (HWND, WORD, WORD, LONG) ;
  13.  
  14. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  15.                     LPSTR lpszCmdParam, int nCmdShow)
  16.      {
  17.      static char szAppName[] = "MidiDevs" ;
  18.      HWND        hwnd ;
  19.      MSG         msg ;
  20.      WNDCLASS    wndclass ;
  21.  
  22.      if (!hPrevInstance)
  23.           {
  24.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  25.           wndclass.lpfnWndProc   = WndProc ;
  26.           wndclass.cbClsExtra    = 0 ;
  27.           wndclass.cbWndExtra    = 0 ;
  28.           wndclass.hInstance     = hInstance ;
  29.           wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  30.           wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  31.           wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  32.           wndclass.lpszMenuName  = NULL ;
  33.           wndclass.lpszClassName = szAppName ;
  34.  
  35.           RegisterClass (&wndclass) ;
  36.       }
  37.  
  38.      hwnd = CreateWindow (szAppName, "MIDI Device Capabilities",
  39.                           WS_OVERLAPPEDWINDOW,
  40.                           CW_USEDEFAULT, CW_USEDEFAULT,
  41.                           CW_USEDEFAULT, CW_USEDEFAULT,
  42.                           NULL, NULL, hInstance, NULL) ;
  43.  
  44.      ShowWindow (hwnd, nCmdShow) ;
  45.      UpdateWindow (hwnd) ;
  46.  
  47.      while (GetMessage (&msg, NULL, 0, 0))
  48.           {
  49.           TranslateMessage (&msg) ;
  50.           DispatchMessage (&msg) ;
  51.           }
  52.      return msg.wParam ;
  53.      }
  54.  
  55. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  56.      {
  57.      static char  *szManuID [] = { "?????",              "MM_MICROSOFT",
  58.                                    "?????"                                  } ;
  59.      static char  *szProdID [] = { "?????",              "MM_MIDI_MAPPER",
  60.                                    "?????",              "MM_SNDBLST_MIDIOUT",
  61.                                    "MM_SNDBLST_MIDIIN",  "MM_SNDBLST_SYNTH",
  62.                                    "MM_SNDBLST_WAVEOUT", "MM_SNDBLST_WAVEIN",
  63.                                    "?????",              "MM_ADLIB",
  64.                                    "MM_MPU401_MIDIOUT",  "MM_MPU401_MIDIIN",
  65.                                    "MM_PC_JOYSTICK",     "?????"            } ;
  66.      static char  *szTechID [] = { "?????",              "MOD_MIDIPORT",
  67.                                    "MOD_SYNTH",          "MOD_SQSYNTH",
  68.                                    "MOD_FMSYNTH",        "MOD_MAPPER",
  69.                                    "?????"                                  } ;
  70.      static char  szBuffer [MAXPNAMELEN + 64] ;
  71.      static short cxChar, cyChar, cxClient, cyClient ;
  72.      HDC          hdc ;
  73.      MIDIINCAPS   mic ;
  74.      MIDIOUTCAPS  moc ;
  75.      PAINTSTRUCT  ps ;
  76.      short        i, x, y, iNumDevs ;
  77.  
  78.      switch (message)
  79.           {
  80.           case WM_CREATE:
  81.                cxChar = LOWORD (GetDialogBaseUnits ()) ;
  82.                cyChar = HIWORD (GetDialogBaseUnits ()) ;
  83.                return 0 ;
  84.  
  85.           case WM_SIZE:
  86.                cxClient = LOWORD (lParam) ;
  87.                cyClient = HIWORD (lParam) ;
  88.                return 0 ;
  89.  
  90.           case WM_PAINT:
  91.                hdc = BeginPaint (hwnd, &ps) ;
  92.  
  93.                SetBkMode (hdc, TRANSPARENT) ;
  94.  
  95.                x = cxChar ;
  96.                y = 0 ;
  97.  
  98.                iNumDevs = midiInGetNumDevs () ;
  99.  
  100.                for (i = 0 ; i < iNumDevs ; i++)
  101.                     {
  102.                     midiInGetDevCaps (i, &mic, sizeof (MIDIINCAPS)) ;
  103.  
  104.                     wsprintf (szBuffer, "mic.wMid: %04X (%s)", mic.wMid,
  105.                               (LPSTR) szManuID [min (mic.wMid,
  106.                                   sizeof (szManuID) / sizeof (szManuID[0]))]) ;
  107.                     OUT
  108.  
  109.                     wsprintf (szBuffer, "mic.wPid: %04X (%s)", mic.wPid,
  110.                               (LPSTR) szProdID [min (mic.wPid,
  111.                                   sizeof (szProdID) / sizeof (szProdID[0]))]) ;
  112.                     OUT
  113.  
  114.                     wsprintf (szBuffer, "mic.vDriverVersion: 0x%04X",
  115.                               mic.vDriverVersion) ;
  116.                     OUT
  117.  
  118.                     wsprintf (szBuffer, "mic.szPname: %s",
  119.                               (LPSTR) mic.szPname) ;
  120.                     OUT
  121.  
  122.                     MoveTo (hdc, x, y) ;
  123.                     LineTo (hdc, x + 39 * cxChar, y) ;
  124.                     }
  125.  
  126.                x = 40 * cxChar ;
  127.                y = 0 ;
  128.  
  129.                iNumDevs = midiOutGetNumDevs () ;
  130.  
  131.                for (i = MIDIMAPPER ; i < iNumDevs ; i++)
  132.                     {
  133.                     midiOutGetDevCaps (i, &moc, sizeof (MIDIOUTCAPS)) ;
  134.  
  135.                     wsprintf (szBuffer, "moc.wMid: %d (%s)", moc.wMid,
  136.                               (LPSTR) szManuID [min (moc.wMid,
  137.                                   sizeof (szManuID) / sizeof (szManuID[0]))]) ;
  138.                     OUT
  139.  
  140.                     wsprintf (szBuffer, "moc.wPid: %d (%s)", moc.wPid,
  141.                               (LPSTR) szProdID [min (moc.wPid,
  142.                                   sizeof (szProdID) / sizeof (szProdID[0]))]) ;
  143.                     OUT
  144.  
  145.                     wsprintf (szBuffer, "moc.vDriverVersion: 0x%04X",
  146.                               moc.vDriverVersion) ;
  147.                     OUT
  148.  
  149.                     wsprintf (szBuffer, "moc.szPname: %s",
  150.                               (LPSTR) moc.szPname) ;
  151.                     OUT
  152.  
  153.                     wsprintf (szBuffer, "moc.wTechnology: %d (%s)",
  154.                               moc.wTechnology,
  155.                               (LPSTR) szTechID [min (moc.wTechnology,
  156.                                   sizeof (szTechID) / sizeof (szTechID[0]))]) ;
  157.                     OUT
  158.  
  159.                     wsprintf (szBuffer, "moc.wVoices: %d", moc.wVoices) ;
  160.  
  161.                     OUT
  162.  
  163.                     wsprintf (szBuffer, "moc.wNotes: %d", moc.wNotes) ;
  164.  
  165.                     OUT
  166.  
  167.                     wsprintf (szBuffer, "moc.wChannelMask: 0x%04X",
  168.                               moc.wChannelMask) ;
  169.                     OUT
  170.  
  171.                     wsprintf (szBuffer, "moc.dwSupport: %08X",
  172.                               moc.dwSupport) ;
  173.                     OUT
  174.  
  175.                     MoveTo (hdc, x, y) ;
  176.                     LineTo (hdc, x + 39 * cxChar, y) ;
  177.                     }
  178.  
  179.            EndPaint (hwnd, &ps) ;
  180.                return 0 ;
  181.  
  182.           case WM_DESTROY:
  183.                PostQuitMessage (0) ;
  184.                return 0 ;
  185.           }
  186.  
  187.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  188.      }
  189.